package com.whk.controller;

import com.whk.pojo.Result;
import com.whk.utils.AliOSSUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 处理上传文件前端请求
 */
@RestController
@Slf4j
public class UploodController {
    @Autowired
    private AliOSSUtils aliOSSUtils;

    /**
     * 上传图片到OSS服务器
     */
    @PostMapping("/upload")
    public Result image(MultipartFile image) throws Exception {
        log.info("上传文件{}成功", image.getOriginalFilename());
        String url = aliOSSUtils.upload(image);//上传文件后，返回该文件的访问路径
        log.info("该文件访问路径{}",url);
        return Result.success(url);
    }
}
